{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 1 1]\n",
      " [2 2 2]]\n"
     ]
    }
   ],
   "source": [
    "A = np.array([1,1,1])\n",
    "B = np.array([2,2,2])\n",
    "#A = np.array([1,1,1])[:,np.newaxis]还可以这么写\n",
    "#B = np.array([2,2,2])[:,np.newaxis]\n",
    "print(np.vstack((A,B)))#vertical stack"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 1 1 2 2 2]\n",
      "(3,) (6,)\n"
     ]
    }
   ],
   "source": [
    "C = np.vstack((A,B))\n",
    "D = np.hstack((A,B))#horizonal stack\n",
    "print(D)\n",
    "print(A.shape,D.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 1 1]]\n",
      "(3, 1)\n"
     ]
    }
   ],
   "source": [
    "print(A[np.newaxis,:])#行加了一个维度\n",
    "print(A[:,np.newaxis].shape)#列加了一个维度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1]\n",
      " [1]\n",
      " [1]]\n",
      "[[2]\n",
      " [2]\n",
      " [2]]\n"
     ]
    }
   ],
   "source": [
    "A = np.array([1,1,1])[:,np.newaxis]\n",
    "B = np.array([2,2,2])[:,np.newaxis]\n",
    "print(A)\n",
    "print(B)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 2 1]\n",
      " [1 2 2 1]\n",
      " [1 2 2 1]]\n"
     ]
    }
   ],
   "source": [
    "C = np.concatenate((A,B,B,A),axis=1)#连接的形式\n",
    "print(C)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
